home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / gnuplotMode.tcl < prev    next >
Encoding:
Text File  |  2001-01-04  |  68.5 KB  |  2,395 lines

  1. ## -*-Tcl-*- (nowrap)
  2.  # ==========================================================================
  3.  # 
  4.  # "gnuplotMode.tcl"
  5.  #                                    created: 08/01/95 {07:59:36 pm}
  6.  #                                last update: 01/04/2001 {22:39:24 PM}
  7.  #  Author: Jeff Schindall
  8.  #  E-mail: <mailto:schindall@nrl.navy.mil>
  9.  #    mail: Naval Research Laboratory
  10.  #          Acoustics Division --- Code 7120
  11.  #          4555 Overlook Ave SW
  12.  #          Washington, DC, 20375 USA ]
  13.  # 
  14.  # gnuplotMode.tcl, Version 2.0       For  gnuplot 3.6
  15.  # 
  16.  # This is a set of TCL proc's that allow the shareware Macintosh
  17.  # text editor Alpha to serve as a front end for GNUPLOT for
  18.  # Macintosh version 3.6. This script requires Alpha 7.4 or later.
  19.  # 
  20.  # This mode was written by Jeff Schindall.  Some code was pinched from
  21.  # other TCL files distributed with Alpha and matlab.tcl.
  22.  # 
  23.  # Just use 'shift-ctrl-g' to launch a gnuplot console
  24.  # 
  25.  # (Note: Vince updated this file for use with Alpha 7.1b10)
  26.  # (Note: Craig updated this file for use with Alpha 7.4)
  27.  # ==========================================================================
  28.  ##
  29.  
  30. # ===========================================================================
  31. #
  32. # Autoload procedures
  33. #
  34.  
  35. alpha::mode GPLT 2.0.1 gnuplotMenu {*.gp *.gnu *.gnp *.gplt *.GP *.GNU *.GNP *.GPLT} {
  36.     gnuplotMenu electricReturn electricTab
  37. } {
  38.     # We require 7.4b21 for prefs handling.
  39.     alpha::package require AlphaTcl 7.4b21
  40.     addMenu gnuplotMenu "•415" GPLT
  41.     set modeCreator(GPLT) GPLT
  42.     set modeCreator(GPSE) GPLT
  43.     newPref sig GnuplotSig GPLT
  44. } help {
  45.     Gnuplot is a command-line driven interactive function plotting utility
  46.     for UNIX, MSDOS, and VMS platforms.  The software is copyrighted but
  47.     freely distributed (i.e., you don't have to pay for it).  It was
  48.     originally intended as a graphical program which would allow scientists
  49.     and students to visualize mathematical functions and data.
  50.  
  51.                         -- <http://www.cs.dartmouth.edu/gnuplot_info.html>
  52.  
  53.     Gnuplot Mode serves as a front end for GNUPLOT for Macintosh version
  54.     3.6.  Alpha acts as Gnuplot's console window.  You can activate the
  55.     console with cmd-1 or using the Console menu item in Alpha's Gnuplot
  56.     menu.  When in console mode you have access to Gnuplot's built-in help.
  57.  
  58.     A simple floating menu lists all text files in the scripts directory of
  59.     gnuplot home dir.  To run a script, just select it from the scripts
  60.     menu.  To edit a script in Alpha, select a script menu item while
  61.     holding down a modifier key (shift, option, command, OR ctrl). 
  62.  
  63.     Modify some of the GPLT mode behaviour by choosing the menu item:
  64.  
  65.     "Config --> Mode Prefs --> Preferences"
  66.  
  67.     FOR 68K USERS ONLY
  68.  
  69.     Recent versions of Alpha (< 6.2) do not have a fully working
  70.     eventHandler procedure.  Thus, you might notice strange behavior in the
  71.     gnuplot console.  The symptoms of the problem are that a new gnuplot
  72.     prompt may not be displayed on the screen after pressing a carriage
  73.     return; or, longer messages may be garbled.
  74.  
  75.     Try the following:
  76.  
  77.     set term post
  78.     plot sin(x)
  79.  
  80.     If you see pages of postscript output, then the eventHandler is
  81.     apparently working.
  82.  
  83.     Keep an eye out for the latest versions of Alpha which will eventually
  84.     solve this problem.
  85.  
  86.     Comments, suggestions, and bug reports should be sent to Jeff at
  87.  
  88.         <jeff@wave.nrl.navy.mil>
  89. }
  90.  
  91. proc gnuplotMenu {} {}
  92.  
  93. namespace eval GPLT {}
  94.  
  95. hook::register mode::init              GPLT::graphButton          GPLT
  96. hook::register mode::editPrefsFile     GPLT::editCurrentModePrefs GPLT
  97. hook::register dialog::modifyModeFlags GPLT::modifyModeFlags      GPLT
  98. hook::register closeHook               GPLT::closeHook            GPLT
  99. hook::register deactivateHook          GPLT::deactivateHook       GPLT
  100. hook::register activateHook            GPLT::activateHook         GPLT
  101.  
  102. # ===========================================================================
  103. #
  104. # ◊◊◊◊ GPLT mode preferences ◊◊◊◊ #
  105.  
  106. # ===========================================================================
  107. #
  108. # remove unused, previously saved preferences
  109.  
  110. # remove unused, previously saved preferences
  111.  
  112. foreach oldvar [list FSIG CREA TYPE] {
  113.     prefs::removeObsolete GPLTmodeVars($oldvar)
  114. }
  115.  
  116. # ===========================================================================
  117. #
  118.  
  119. # ===========================================================================
  120. #
  121. # Standard preferences recognized by various Alpha procs
  122. #
  123.  
  124. newPref var  prefixString {# } GPLT
  125. newPref var  tabSize {3} GPLT
  126. newPref var  prefixString {# } GPLT
  127. newPref var  wordBreak {[a-zA-Z0-9_]+} GPLT
  128. newPref var  wordBreakPreface {[^a-zA-Z0-9_]} GPLT
  129. newPref flag wordWrap {0} GPLT
  130.  
  131. # ===========================================================================
  132. #
  133. # Flag preferences
  134. #
  135.  
  136. newPref flag NevrSavHist {0} GPLT
  137. newPref flag LiveHist {1} GPLT
  138. newPref flag GraphButton {1} GPLT
  139. newPref flag EventHandler {1} GPLT
  140.  
  141. # ===========================================================================
  142. #
  143. # Variable preferences
  144. #
  145.  
  146. # The "Gnuplot Home Page" menu item will send this url to your browser.
  147. newPref url gnuplotHomePage      {http://www.cs.dartmouth.edu/gnuplot_info.html}      GPLT
  148.  
  149. # ===========================================================================
  150. #
  151. # Color preferences
  152. #
  153.  
  154. newPref color bracesColor blue   GPLT  {GPLT::colorizeGPLT}
  155. newPref color commandColor blue  GPLT  {GPLT::colorizeGPLT}
  156. newPref color commentColor red   GPLT  {stringColorProc}
  157. newPref color stringColor green  GPLT  {stringColorProc}
  158.  
  159. regModeKeywords -e {#} \
  160.   -c $GPLTmodeVars(commentColor) \
  161.   -s $GPLTmodeVars(stringColor) GPLT {}
  162.   
  163. ### Commands ###
  164.  
  165. set gpCommands { 
  166.     \\ console set show plot splot autoscale binary boxxyerrorbars bugs
  167.     call cd clear co-ordinates comments environment exit expressions fit if
  168.     introduction line-editing load pause plot print pwd quit replot reread
  169.     reset save seeking-assistance set shell show splot startup style
  170.     substitution test update userdefined xyerrorbars xerrorbars yerrorbars
  171.  
  172.     "Copyright(C) 1986 - 1997" 
  173.     "Copyright(C) 1986 - 1998"
  174.     "Copyright(C) 1986 - 1999"
  175.     "Copyright(C) 1986 - 2000"
  176.     "Copyright(C) 1986 - 2001"
  177. }
  178.  
  179. ### GREEN WORDS ###
  180.  
  181. set gpGreenWords {
  182.     ranges         smooth         data-file      datafile
  183.     parametric     locale         nosquare       errorbars
  184.     gnuplot        gnuplot>       term           square
  185.     angles         arrow          autoscale      bar
  186.     bmargin        border         boxwidth       clabel
  187.     clip           cntrparam      contour        data
  188.     dgrid3d        dummy          encoding       format
  189.     function       grid           hidden3d       isosamples
  190.     key            keytitle       label          lmargin
  191.     logscale       mapping        margin         missing
  192.     multiplot      mx2tics        mxtics         my2tics
  193.     mytics         mztics         noarrow        noautoscale
  194.     noborder       noclabel       noclip         nodgrid3d
  195.     nokey          nolabel        nologscale     nomultiplot
  196.     nomx2tics      nomxtics       nomy2tics      nomytics
  197.     nomztics       noparametric   nopolar        nosurface
  198.     nox2dtics      nox2mtics      nox2tics       nox2zeroaxis
  199.     noxdtics       noxmtics       noxtics        noxzeroaxis
  200.     noy2dtics      noy2mtics      noy2tics       noy2zeroaxis
  201.     noydtics       noymtics       noytics        noyzeroaxis
  202.     nozdtics       nozeroaxis     nozmtics       noztics
  203.     offsets        origin         output         parametric
  204.     pointsize      polar          punctuation    rmargin
  205.     rrange         samples        size           specify
  206.     style          surface        syntax         terminal
  207.     tics           ticscale       ticslevel      time
  208.     timefmt        title          tmargin        trange
  209.     urange         view           vrange         x2dtics
  210.     x2label        x2mtics        x2range        x2tics
  211.     x2zeroaxis     xdata          xdtics         xlabel
  212.     xmtics         xrange         xtics          xzeroaxis
  213.     y2dtics        y2label        y2mtics        y2range
  214.     y2tics         y2zeroaxis     ydtics         ylabel
  215.     ymtics         yrange         ytics          yzeroaxis
  216.     zdtics         zero           zeroaxis       zlabel
  217.     zmtics         zrange         ztics
  218.     threaded
  219. }
  220.  
  221. ### CYAN WORDS ###
  222.  
  223. set gpCyanWords  {   
  224.     post mac     macintosh      texdraw
  225.     aifm           atari          dumb           enhpost
  226.     epson          epson180       epson60        fig
  227.     gpic           hpljii         imagen         iris4d
  228.     latex          linux          mf             mif
  229.     mtos           nec-cp6        pbm            pcl5
  230.     postscript     pslatex        regis          starc
  231.     table          tandy60        tgif           uniplex
  232.     vdi            windows        unknown        pstricks
  233.     png            dxf            cgm            gif
  234.     emtex          pstex          eepic          tpic
  235.     pstricks       texdraw
  236. }
  237.  
  238. # ===========================================================================
  239. #
  240. #
  241. # Color keywords for GPLT mode
  242. #
  243.  
  244. proc GPLT::colorizeGPLT {{pref ""}} {
  245.     
  246.     global GPLTmodeVars gpCommands gpGreenWords gpCyanWords GPLTcmds
  247.     
  248.     set GPLTcmds [lsort [lunique [concat \
  249.       $gpCommands $gpGreenWords $gpCyanWords \
  250.       ]]]
  251.  
  252.     regModeKeywords -a \
  253.       -i "\}" -i "\{"  -i ">" -i "<" -i ")" -i "("  -i "/" -I "\\"  \
  254.       -i "\]" -i "\[" -i "\$" -i "\'" -i "\`" -i ">" -i "<" -i "^" -i "_" \
  255.       -I $GPLTmodeVars(bracesColor) \
  256.       -k $GPLTmodeVars(commandColor) GPLT $gpCommands
  257.     regModeKeywords -a -k green GPLT $gpGreenWords
  258.     regModeKeywords -a -k cyan  GPLT $gpCyanWords
  259.     if {$pref != ""} {refresh}
  260. }
  261.  
  262. # Call this now.
  263.  
  264. GPLT::colorizeGPLT
  265.  
  266. # ===========================================================================
  267. #
  268. #  global variables
  269. #
  270.  
  271. ensureset gp_CREA                  {ALFA}
  272. ensureset gp_TYPE                  {TEXT}
  273. ensureset gp_CreatorList [list] 
  274. ensureset gp_TypeList [list] 
  275. ensureset gp_CreatorNames [list] 
  276. ensureset gp_GEOM [list]
  277. ensureset gp_HistGEOM [list ]
  278. ensureset headerSuffices {$GPLTmodeSuffixes}
  279. ensureset sourceSuffices {$GPLTmodeSuffixes}
  280.  
  281. if {[llength $gp_CreatorList] == 0 \
  282.  || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  283.  || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  284.     set gp_CreatorList [list ALFA GPLT]
  285.     set gp_TypeList [list  TEXT TEXT]
  286.     set gp_CreatorNames [list  alpha gnuplot]
  287.     set gp_CREA {ALFA} 
  288.     set gp_TYPE {TEXT}
  289. }
  290.  
  291. set gp_CommandHist [list]
  292. set gp_CommandNum 0
  293.  
  294. set gp_Prompt       "gnuplot> "
  295. set gp_MultiPrompt  "multiplot> "
  296. set gp_ContPrompt   "> "
  297. set gp_HelpPrompt   ": "
  298.  
  299. set gp_Prompts [list $gp_Prompt $gp_ContPrompt $gp_MultiPrompt ]
  300.  
  301. set gp_Console  "  gnuplot  "
  302. set gp_Hist     "  history  "
  303. set gp_Graph     "  graph  "
  304. set gp_sl [list]
  305.  
  306. set gpTermCt 0
  307.  
  308. set gp_Launched {0}
  309.  
  310. # ===========================================================================
  311. # ◊◊◊◊ Key Bindings, Electrics ◊◊◊◊ #
  312.  
  313. # ===========================================================================
  314. #
  315. #  Bind some keys
  316. #
  317.  
  318. # Editing .gnu files
  319.  
  320. Bind '\r' <z>  GPLT::doLine             "GPLT"
  321.  
  322. # Command Window
  323.  
  324. Bind '\r'      GPLT::carriageReturn     "GPLT"
  325. Bind up        GPLT::prevCommand        "GPLT"
  326. Bind down      GPLT::nextCommand        "GPLT"
  327. Bind '1'  <z>  GPLT::console            "GPLT"
  328. Bind '2'  <z>  GPLT::activate           "GPLT"
  329. Bind '3'  <z>  GPLT::dumpHistory        "GPLT"
  330. Bind 'f'  <sc> GPLT::saveAndExecute     "GPLT"
  331.  
  332. # Setting the order of precedence for completions.
  333.  
  334. set completions(GPLT) {
  335.     completion::cmd completion::electric completion::word
  336. }
  337.  
  338. set GPLTelectrics(plot)   " \[••:••\] \[••:••\] ••\r••"
  339. set GPLTelectrics(set)    " •• \[••: ••\]••\r••"
  340. set GPLTelectrics(pause)  " •• \"••\"\r••"
  341.  
  342. # ===========================================================================
  343. #
  344. #  Carriage return for command window
  345. #
  346.  
  347. proc GPLT::carriageReturn {} {
  348.     global gp_CommandHist gp_CommandNum  gp_Console gp_Hist gp_Graph
  349.     
  350.     # enter only if cr in console window...
  351.     set wins [winNames]
  352.     if { [lsearch $wins $gp_Console ]  == 0  } {
  353.     setWinInfo -w $gp_Console dirty 0
  354.     set pos [getPos]
  355.  
  356.     # I look for > and : instead of the proper prompts... Hmmm...
  357.     # if -1 then we are not on an input line...
  358.     # or we could be waiting for a pause...
  359.     # which should be on the last line...
  360.     set ind [string first ">" [getText [lineStart $pos] $pos] ]
  361.     if {$ind < 0} {
  362.         set ind [string first ":" [getText [lineStart $pos] $pos] ]
  363.         if {$ind < 0} {
  364.         endOfBuffer
  365.         # just send a cr to the server
  366.         insertText "\r"
  367.         GPLT::sendCommand [getText [lineStart $pos] $pos] 400
  368.         return
  369.         }
  370.     }
  371.     set lStart [pos::math [lineStart $pos]+ [expr $ind+2]]
  372.     endOfLine
  373.     set lEnd  [getPos]
  374.     set scriptName [getText $lStart $lEnd]
  375.     insertText "\r"
  376.     # if not on last line, then replace text on last line...
  377.     GPLT::sendCommand "$scriptName"  102
  378.     } elseif {[lsearch $wins $gp_Hist ] == 0} {
  379.     # execute the current command in the history window...
  380.     GPLT::histgotoMatch
  381.     } else {
  382.     insertText "\r"
  383.     }
  384. }
  385.  
  386. # ===========================================================================
  387. # ◊◊◊◊ Command Double Click ◊◊◊◊ #
  388. # In GNUc mode, cmd-double-click highlights area btween consecutive
  389. # gnuplot prompts
  390. #
  391.  
  392. proc GPLT::DblClick {from to} {
  393.     
  394.     global gp_Prompts
  395.     
  396.     # First find "gnuplot> " prompt above and below cursor entry...
  397.     # don't forget to deal with "multiplot> " and "> "
  398.     
  399.     set gp1 [list]
  400.     foreach gp $gp_Prompts {lappend gp1 [search -n -f 0 -r 1 $gp $from] }
  401.     set firstmatch [lindex [lindex $gp1 0 ] 0]
  402.     foreach el $gp1 {
  403.     if {[pos::compare [lindex $el 1] > $firstmatch]} {
  404.         set firstmatch [lindex $el 0]
  405.     }
  406.     }
  407.     
  408.     if {$firstmatch == {}} {
  409.     message "You are not between prompts"
  410.     return
  411.     } else {
  412.  
  413.     set firstmatch [nextLineStart $firstmatch]
  414.     endOfBuffer
  415.     set lastmatch [getPos ]
  416.     set gp1 [list]
  417.     foreach gp $gp_Prompts {lappend gp1 [search -n -f 1 -r 1   $gp $from] }
  418.     foreach el $gp1 {
  419.         if {[lindex $el 1]!={} && [pos::compare [lindex $el 0] < $lastmatch] } {
  420.         set lastmatch $el
  421.         }
  422.     }
  423.     if {$lastmatch == {}} {
  424.         message "You are not between prompts"
  425.         return
  426.     } else {
  427.         
  428.         goto $lastmatch
  429.         beginningOfLine
  430.         select $firstmatch [getPos]
  431.     }
  432.     }
  433. }
  434.  
  435. # ===========================================================================
  436. #
  437. # ◊◊◊◊ Mark File ◊◊◊◊ #
  438.  
  439. proc GPLT::MarkFile {{type ""}} {
  440.     
  441.     message "Marking File …"
  442.     
  443.     set count 0
  444.     set markExpr {^plot([\t ]+\[)}
  445.     # Mark the file
  446.     set pos [minPos]
  447.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $markExpr $pos} match]} {
  448.     incr count
  449.     set posBeg [lindex $match 0]
  450.     set posEnd [nextLineStart $posBeg]
  451.     if {[pos::math $posEnd > [maxPos]]} {set posEnd [maxPos]} 
  452.     set line   [string trimright [getText $posBeg $posEnd]]
  453.     # Get rid of braces.
  454.     regsub -all {\{|\[} $line {(} line
  455.     regsub -all {\}|\]} $line {)} line
  456.     if {[string length $line] > 35} {
  457.         set line "[string range $line 0 35] ..."
  458.     } 
  459.     setNamedMark $line $posBeg $posBeg $posBeg
  460.     set pos $posEnd
  461.     }
  462.     message "This file contains $count plot commands."
  463. }
  464.  
  465. # ◊◊◊◊ --------------------• ◊◊◊◊ #
  466.  
  467. # ===========================================================================
  468. # ◊◊◊◊ Gnuplot Menu Definition ◊◊◊◊ #
  469.  
  470. # ===========================================================================
  471. #
  472. #  gnuplot Menu
  473. #
  474.  
  475. Menu -n    $gnuplotMenu -p GPLT::gnuplotMenuProc    {
  476.     "gnuplotHomePage"
  477.     "gnuplotHelp"
  478.     "/S<U<BswitchTo gnuplot"
  479.     "/Q<Uquit gnuplot"
  480.     "(-"
  481.     "/1<Bconsole"
  482.     "/2<Bgraph"
  483.     "/3<Bhistory"
  484.     "(-"
  485.     "<E<SgraphButton"
  486.     "<S<OkillGraphButton"
  487.     "setWorkingFolder…"
  488.     "/P<UchoosePlotFile…"
  489.     "/L<Uload…"
  490.     {Menu -n "saveSettings" -p GPLT::gnuplotMenuProc  {
  491.     "/S<Uall"
  492.     "(-"
  493.     "setCmds" 
  494.     "functions"
  495.     "variables"
  496.     }}
  497.     "(-"
  498.     "/N<UnewScriptWin"
  499.     "/F<UsaveAndExecute"
  500.     "(-"
  501.     {Menu  -s -m -n mathFunctions -p GPLT::gnuplotMenuProc  {
  502.     {Menu  -s -m -n Trigonometric -p GPLT::gnuplotMenuProc  {
  503.         "cos"
  504.         "tan"
  505.         "sin"
  506.     }}
  507.     {Menu  -s -m -n InverseTrig -p GPLT::gnuplotMenuProc  {
  508.         "acos"
  509.         "asin"
  510.         "atan"     
  511.     }}
  512.     {Menu  -s -m -n Hyperbolic -p GPLT::gnuplotMenuProc  {
  513.         "cosh"
  514.         "sinh"
  515.         "tanh"
  516.     }}
  517.     {Menu  -s -m -n special -p GPLT::gnuplotMenuProc  {
  518.         "erf"
  519.         "erfc"
  520.         "inverf"
  521.         "(-"
  522.         "gamma"
  523.         "igamma"
  524.         "lgamma"
  525.         "(-"
  526.         "ibeta"
  527.     }}
  528.     {Menu  -s -m -n bessel -p GPLT::gnuplotMenuProc  {
  529.         "besj0"
  530.         "besj1"
  531.         "besy0"
  532.         "besy1"     
  533.     }}
  534.     "(-"
  535.     "abs"
  536.     "arg"
  537.     "sgn"
  538.     "sqrt"
  539.     "(-"
  540.     "exp"
  541.     "log"
  542.     "log10"
  543.     "(-"
  544.     "ceil"
  545.     "floor" 
  546.     "rand"
  547.     "norm"
  548.     "invnorm"
  549.     "(-"
  550.     "real" 
  551.     "imag"
  552.     "int"
  553.     }}
  554.     "(-"
  555.     "/M<UdoSelection"
  556.     "doLine"
  557.     "(-"
  558.     {Menu -n gnuplotOptions -p GPLT::gnuplotMenuProc     {
  559.     "setPointSize…"
  560.     "(-"
  561.     "/H<UclearHistory"
  562.     "(-"
  563.     {Menu -n setOutputCreator -p GPLT::gnuplotMenuProc     {
  564.         "select…"
  565.         "add…"
  566.         "delete…"
  567.     }}
  568.     }}
  569. }
  570.  
  571. proc GPLT::gnuplotMenuProc {menu item} {
  572.     
  573.     global GPLTmodeVars
  574.  
  575.     switch $item {
  576.         "add"                           { GPLT::addCreator }
  577.         "all"                           { GPLT::saveSettings "" }
  578.         "choosePlotFile"                { GPLT::choosePlotFile }
  579.         "clearHistory"                  { GPLT::clearHistory }
  580.         "console"                       { GPLT::console }
  581.         "delete"                        { GPLT::deleteCreator }
  582.         "doLine"                        { GPLT::doLine }
  583.         "doSelection"                   { GPLT::doSelection }
  584.         "functions"                     { GPLT::saveSettings "fun" }
  585.         "gnuplot"                       { GPLT::activate }
  586.         "gnuplotHelp"                   { package::helpFile "GPLT" }
  587.         "gnuplotHomePage"               { url::execute $GPLTmodeVars(gnuplotHomePage)}
  588.         "graph"                         { GPLT::activate }
  589.         "graphButton"                   { GPLT::killGraphButton ; GPLT::graphButton 1 } 
  590.         "gxText"                        { GPLT::dialog "gxtx" }
  591.         "history"                       { GPLT::dumpHistory }
  592.         "killGraphButton"               { GPLT::killGraphButton }
  593.         "labels"                        { GPLT::dialog "labl" }
  594.         "labels"                        { GPLT::dialog "labl" }
  595.         "line styles"                   { GPLT::dialog "line" }
  596.         "load"                          { GPLT::loadScript }
  597.         "newScriptWin"                  { GPLT::newWindow }
  598.         "offsets"                       { GPLT::dialog "oset" }
  599.         "quitgnuplot"                   { GPLT::quit }
  600.         "saveAndExecute"                { GPLT::saveAndExecute }
  601.         "select"                        { GPLT::selectCreator }
  602.         "setCmds"                       { GPLT::saveSettings "set" }
  603.         "setPointSize"                  { GPLT::setPTSZ }
  604.         "setWorkingFolder"              { GPLT::setCWD }
  605.         "switchTognuplot"               { GPLT::activate }
  606.         "text format"                   { GPLT::dialog "text" }
  607.         "variables"                     { GPLT::saveSettings "var" }
  608.         default                         {
  609.             insertText [string tolower $item ] ()
  610.             backwardChar
  611.         }
  612.     }
  613. }
  614.  
  615. # ===========================================================================
  616. # ◊◊◊◊ Event Handlers ◊◊◊◊ #
  617.  
  618. # ===========================================================================
  619. #
  620. #  setup the event handler for Alpha/gnuplot interapp communication
  621. #  This file only works with Alpha 7.0 or newer so we assume
  622. #  eventHandling actually works.
  623. #
  624.  
  625. # Setup event Handler for STDOUT
  626. eventHandler GPSE OUTP "GPLT::sTDOUThandler"
  627.  
  628. # Setup event Handler for systems w/o ThreadManager
  629. eventHandler GPSE ERRP "GPLT::sTDERRhandler"
  630.  
  631. # *ICInitializeCommand // This initializes the console.
  632. # Alpha eventhandler is needed.
  633. # 'GPIC init'
  634. eventHandler GPIC init "GPLT::consoleH"
  635. #
  636. # *ICInitializePath // sends the working directory as
  637. # stored in preferences.
  638. # Since you aren't displaying the working directory anywhere,
  639. # we can ignore
  640. # this for now.
  641. # 'GPIC path', contains a string in the direct object.
  642. eventHandler GPIC path "GPLT::sendPath"
  643. #
  644. # ICExecute // Tells the console to execute a gnuplot command.
  645. # I can't think
  646. # of a reason for this one in Alpha.  The menuing system uses
  647. # this one in the current console.  We could define an event however.
  648. #
  649. # ICInsertCommand // Might be slick.  An example of what this
  650. # does is where
  651. # functions get pasted into the command line.  Not absolutely necessary
  652. # though.
  653. # 'GPIC' 'inse'
  654. eventHandler GPIC inse "GPLT::iNSEhandler"
  655. #
  656. # ICComeToFront  // The function will bring Alpha to the front.
  657. # No handler needed.
  658. #
  659. # *ICBringGnuplotToFront // Handler needed.  When you get this one, bring
  660. # gnuplot to the front.
  661. # 'GPIC tofr'
  662. eventHandler GPIC tofr "GPLT::activateH"
  663. #
  664. # *ICHandleAEReply // You'll get this one if somebody used a
  665. # gnuplot menu to
  666. # do something which necessitated a reply from gnuplot. The
  667. # gnuplot interface
  668. # will pass the reply to you for display.
  669. # 'GPIC repl', handle this one just like the reply from your exec event.
  670. eventHandler GPIC repl "GPLT::sTDERRhandler"
  671. #
  672. # *ICMakeNewDocument  // It sounds like this one is working already.
  673. # 'core crel'
  674. eventHandler core crel "GPLT::newWindowH"
  675. #
  676. # *ICOpenDocument // Alpha already knows about this one.
  677. # --already defined in alpha---
  678.  
  679. # The event 'GPIC' 'cbye' is now sent whenever gnuplot quits.
  680. # This will let you close the console if somebody quits
  681. # gnuplot some other way. You could
  682. # use this to eliminate your 'quit' trapping if you want.
  683. eventHandler GPIC cbye "GPLT::closeH"
  684. # I also defined a new event: 'GPIC' 'EXEC'.  All you need to
  685. # do is take the
  686. # data and send it back to gnuplot as a 'GPSE' 'exec' event.
  687. # This is a kludge
  688. # to make the commands in the gnuplot app menus work.
  689. # It will eventually go away.
  690. eventHandler GPIC EXEC "GPLT::kludge"
  691.  
  692. proc GPLT::kludge {it} {
  693.     set outit  [GPLT::filtercurlyq $it]
  694.     GPLT::sTDERR $outit
  695.     if { $it == "Unable to find process" } GPLT::quit
  696.     return 0
  697. }
  698.  
  699. proc GPLT::sTDERRhandler {it} {
  700.     global gp_cwd
  701.     set outit  [GPLT::filtercurlyq $it]
  702.     GPLT::extractPath $it
  703.     GPLT::results $outit
  704.     if { $it == "Unable to find process" } GPLT::quit
  705.     return 0
  706. }
  707.  
  708. proc GPLT::sTDOUThandler {it} {
  709.     global gp_cwd gp_Out gpTermCt
  710.     global gp_Console gp_Graph
  711.     global GPLTmodeVars gp_Launched gp_GEOM
  712.     global gp_Prompt  gp_cwd gnuplotMenu
  713.     
  714.     set outit  [GPLT::filtercurlyq $it]
  715.     GPLT::extractPath $it
  716.     set wins [winNames]
  717.     
  718.     set itLen [ string length "$it" ]
  719.     set termID [ string range "$outit" 0 20 ]
  720.     set termType [ string range "$it" [expr $itLen -25] [expr $itLen -1] ]
  721.     
  722.     if { [ string first "Sorry," "$termID" ] == 0 } {
  723.     insertText -w  $gp_Console "\n$outit"
  724.     return
  725.  
  726.     } elseif { [ string first "% GNUPLOT: LaTeX" "$termID" ] == 0 } {       
  727.     incr gpTermCt 1
  728.     # set gp_Out [getline "Enter name of output console?" "* TeX output $gpTermCt *" ]
  729.     set gp_Out "* TeX output $gpTermCt *"
  730.     set theMode "TeX"
  731.  
  732.     } elseif { [string first "%!PS-Adobe" "$termID" ] == 0 } {
  733.     incr gpTermCt 1
  734.     # set gp_Out [getline "Enter name of output console?" "* PS output $gpTermCt *" ]
  735.     set gp_Out "* PS output $gpTermCt *"
  736.     set theMode "PS"
  737.  
  738.     } elseif { [string first "<MIFFile 3.00>" "$termID" ] == 0 } {
  739.     incr gpTermCt 1
  740.     # set gp_Out [getline "Enter name of output console?" "* MIF output $gpTermCt *" ]
  741.     set gp_Out "* MIF output $gpTermCt *"
  742.     set theMode "PS"
  743.  
  744.     } elseif { [string first "% GNUPLOT: dxf" "$termID" ] >= 0 } {
  745.     incr gpTermCt 1
  746.     # set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  747.     set gp_Out "* misc output $gpTermCt *"
  748.     set theMode "TEXT"
  749.  
  750.     } elseif { [string first "if unknown cmbase" "$termID" ] == 0 } {
  751.     incr gpTermCt 1
  752.     # set gp_Out [getline "Enter name of output console?" "* MF output $gpTermCt *" ]
  753.     set gp_Out "* MF output $gpTermCt *"
  754.     set theMode "TeX"
  755.  
  756.     } elseif { [string first "#Curve" "$termID" ] == 0 } {
  757.     incr gpTermCt 1
  758.     # set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  759.     set gp_Out"* misc output $gpTermCt *"
  760.     set theMode "TEXT"
  761.  
  762.     } elseif { [ string index "$termID" 0  ] == " " && [ string first "TERM:“dumb”" "$termType" ] > 0 } {
  763.     set ns "\n"
  764.     append ns $outit
  765.     set outit "$ns"
  766.     set gp_Out $gp_Console
  767.     # set theMode "TEXT"
  768.  
  769.     } elseif { ![info exists gp_Out ] || [lsearch $wins $gp_Out ] < 0 } {
  770.     incr gpTermCt 1
  771.     # set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  772.     set gp_Out "* misc output $gpTermCt *"
  773.     set theMode "TEXT"
  774.     }
  775.     
  776.     if { $gp_Out == "" } {set gp_Out $gp_Console }
  777.     
  778.     if {  [lsearch $wins $gp_Out ]  < 0 } {
  779.     new  -n $gp_Out -m $theMode
  780.     # set wins [winNames]
  781.     set gp_Out [lindex [winNames] 0]
  782.     } else {
  783.     # catch [ bringToFront $gp_Out ] ans
  784.     # if { ![info exists ans] } { return }
  785.     }
  786.     
  787.     insertText -w $gp_Out $outit
  788.     GPLT::console
  789.     if { $it == "Unable to find process" } GPLT::quit
  790.     return 0
  791. }
  792.  
  793. proc GPLT::iNSEhandler {it} {
  794.     global gp_Console gp_TYPE gp_CREA GnuplotSig
  795.     set res [GPLT::filtercurlyq $it]
  796.     set wins [winNames]
  797.     if { ( "$res" != "\n" ) && ( "$res" != "" ) && ( "$res" != "\r" ) } {
  798.     if { [ lsearch $wins $gp_Console  ] >= 0} {
  799.         bringToFront $gp_Console
  800.     }
  801.     }
  802.     
  803.     goto [maxPos]
  804.     insertText -w $gp_Console $res
  805.     
  806.     
  807.     set paren  [string first "()" $res ]
  808.     
  809.     if { $paren >= 1 } {
  810.     goto [pos::math [maxPos] - $paren + 2]
  811.     }
  812.     
  813.     if { "$res" == "\r" }  {
  814.     GPLT::sendCommand "" 3600
  815.     } elseif { "$res" == "\n" }  {
  816.     GPLT::sendCommand "" 3600
  817.     } elseif { "$res" == "" }  {
  818.     GPLT::sendCommand "" 3600
  819.     } else {
  820.     return 0
  821.     }
  822.     
  823.     
  824. }
  825.  
  826. # ===========================================================================
  827. #
  828. #  Send a command to gnuplot
  829. #
  830.  
  831. proc GPLT::sendCommand { mycommand tmout} {
  832.     global GPLTmodeVars gnuplotMenu  gp_CommandHist gp_Rsp  gp_CommandNum
  833.     global gp_Prompts gp_Launched
  834.     
  835.     watchCursor
  836.     #    GPLT::console
  837.     
  838.     set tmout 300
  839.     # display command on the last line of the console if its not already there
  840.     GPLT::dispCommand "$mycommand"
  841.     if { [string trim $mycommand '\r'] != {} } {
  842.     GPLT::addToHist $mycommand
  843.     }
  844.     
  845.     # send gnuplot a command
  846.     # display the stderr results on the screen
  847.     # The eventHandler above will display the stdout results first
  848.     set stderr [GPLT::sTDERR "$mycommand\r"  $tmout ]
  849.     
  850.     # Null stderr can mean two things.
  851.     #   (1) a pause
  852.     #   (2) if no thread manager available, it could mean go back
  853.     #       and retrieve the stderr which will help 68k systems
  854.     #       work since eventHandler is broken in 6.01
  855.     
  856.     # This can probably be cleaned up with a little effort
  857.     # What I'm doing in the next line is taking care of the
  858.     # non-threaded macs...
  859.     # which always return "".  Its harmless otherwise.
  860.     # if {$stderr == ""  && $mycommand != "" } { set stderr [GPLT::sTDERR "" $tmout ] }
  861.     # if { $GPLTmodeVars(EventHandler) == "0" &&  $stderr == "" } { set stderr "gnuplot> " }
  862.     if { $stderr != "" } {
  863.     GPLT::results     "$stderr"
  864.     } else {
  865.     # GPLT::results ""
  866.     }
  867.     
  868.     blink [getPos]
  869. }
  870.  
  871. proc GPLT::sendPath { dummyVar } {
  872.     global gp_cwd
  873.     # display current path on status bar
  874.     set gp_cwd [ GPLT::filtercurlyq $dummyVar ]
  875.     message "Current gnuplot Path ==> $gp_cwd"
  876. }
  877.  
  878. proc GPLT::consoleH { dummyVar } {
  879.     GPLT::console
  880.     # this is a dummy routine
  881. }
  882.  
  883. proc GPLT::newWindowH { dummyVar } {
  884.     switchTo 'ALFA'
  885.     GPLT::newWindow
  886.     # this is a dummy routine
  887. }
  888.  
  889. proc GPLT::activateH { dummyVar } {
  890.     GPLT::activate
  891.     # this is a dummy routine
  892. }
  893.  
  894. proc GPLT::closeH { dummyVar } {
  895.     GPLT::quit
  896.     # this is a dummy routine
  897. }
  898.  
  899. # ===========================================================================
  900. #
  901. #  Find and launch gnuplot
  902. #
  903.  
  904. proc GPLT::check {} {
  905.     global gnuplotMenu gp_Launched GPLTmodeVars
  906.     
  907.     # Check if gnuplot app is running.  If not, open the app named in
  908.     # $ (if defined) or have the user select an app via a
  909.     # standard file dialog.  Leave the gnuplot app in the background.
  910.     
  911.     if {![catch {app::launchAnyOfThese {GPSE GPLT} GnuplotSig}]} {
  912.     set gp_Launched 1
  913.     enableMenuItem $gnuplotMenu "quit gnuplot" on
  914.     enableMenuItem $gnuplotMenu "graph" on
  915.     enableMenuItem $gnuplotMenu "history" on
  916.     enableMenuItem $gnuplotMenu "saveSettings" on
  917.     enableMenuItem gnuplotOptions "setPointSize…" on
  918.     enableMenuItem $gnuplotMenu "setWorkingFolder…" on
  919.     enableMenuItem $gnuplotMenu "choosePlotFile…"     on
  920.     return 0
  921.     } else {
  922.     return -1
  923.     }
  924. }
  925.  
  926. # ===========================================================================
  927. #
  928. # ◊◊◊◊ Console ◊◊◊◊ #
  929. #
  930.  
  931. # ===========================================================================
  932. #
  933. #  Goto command window
  934. #
  935.  
  936. proc GPLT::console {  } {
  937.     global gp_Console  GPLTmodeVars
  938.     global gp_Launched gp_Prompt
  939.     
  940.     # Check if gnuplot app is running.  If not, open the app named in
  941.     # $ (if defined) or have the user select an app via a
  942.     # standard file dialog.  Leave the gnuplot app in the background.
  943.     
  944.     set wins [winNames]
  945.     if { [lsearch $wins $gp_Console ]  >= 0} {
  946.     bringToFront $gp_Console
  947.     goto [maxPos]
  948.     } else   {
  949.     eventHandler GPIC cbye "GPLT::closeH"
  950.     GPLT::newConsole
  951.     }
  952. }
  953.  
  954. # ===========================================================================
  955. #
  956. #  Create  command window
  957. #
  958.  
  959. proc GPLT::newConsole { } {
  960.     global  gp_Console gp_Graph  gp_Path
  961.     global  GPLTmodeVars gp_Launched gp_GEOM GPLT::graphMenu
  962.     global gp_Prompt  gp_cwd gnuplotMenu  gp_home gp_scriptItems
  963.     
  964.     if {[llength $gp_GEOM] != "4" } {
  965.     new -n $gp_Console -m GPLT
  966.     set gp_GEOM [ getGeometry $gp_Console ]
  967.     }
  968.     set wd [lindex $gp_GEOM 2]
  969.     set ht [lindex $gp_GEOM 3]
  970.     set top [lindex $gp_GEOM 1]
  971.     set left [lindex $gp_GEOM 0]
  972.     set gY [expr $top - 15]
  973.     set gX [expr $left + $wd + 5]
  974.     set gW [expr 72 ]
  975.     set gH [expr 50 ]
  976.     
  977.     set wins [winNames]
  978.     if {  [lsearch $wins $gp_Console ]  < 0 } {
  979.     new -g $left $top $wd $ht -n $gp_Console -m GPLT
  980.     }
  981.     catch { setWinInfo -w $gp_Console shell 1 } jjj
  982.     GPLT::graphButton
  983.     if { $GPLTmodeVars(LiveHist) } GPLT::dumpHistory
  984.     insertText -w $gp_Console  "\nWelcome to Alpha's gnuplot 3.6 shell.\n"
  985.     GPLT::check
  986.     bringToFront $gp_Console
  987.     
  988.     set res [ GPLT::sTDERR ""  3600 ]
  989.     insertText -w $gp_Console "$res"
  990.     
  991.     # The following is a huge kludge...to deal with accidentally
  992.     # closing the gnuplot window
  993.     if    { $res == "" }    {
  994.     GPLT::results "gnuplot> "
  995.     }
  996.     # end kludge
  997.     
  998.     # Now setup the CLIE
  999.     if {[string first "Using threaded console."  $res ] != {-1} \
  1000.       | [string first "ppc" [string tolower $res ] ] != {-1}  } {
  1001.     set ress [GPLT::sTDERR "" 3600 ]
  1002.     }
  1003.     
  1004.     set gp_home "$gp_cwd"
  1005.     append gp_home "Scripts:*"
  1006.     
  1007.     
  1008.     set cdir [pwd]
  1009.     set gp_Path "$gp_home"
  1010.     
  1011.     GPLT::rebuildScriptMenu
  1012.     cd "$cdir"
  1013.     
  1014.     set gp_home [string range "$gp_home" 0 [expr [string length "$gp_home" ] -2 ] ]
  1015.     message "Current gnuplot Path ==> $gp_cwd"
  1016.     
  1017. }
  1018.  
  1019. # ===========================================================================
  1020. #
  1021. #  Rebuild the script menu
  1022. #
  1023.  
  1024. proc GPLT::rebuildScriptMenu {} {
  1025.     global gp_cwd GPLT::graphMenu gp_scriptItems gp_openItems gp_Path
  1026.     
  1027.     set gp_scriptItems [list]
  1028.     set gp_openItems [list]
  1029.     set gp_home "$gp_Path"
  1030.     
  1031.     set gp_sl [ GPLT::scriptList "$gp_home" "Scripts" ]
  1032.     set gp_sm [concat Menu -m -n "Scripts" -p GPLT::scriptMenuItems [list "$gp_sl"]  ]
  1033.     
  1034.     # kill the current floating menu (if any)
  1035.     GPLT::killGraphButton
  1036.     
  1037.     Menu  -n "${GPLT::graphMenu}" -p gnuplotMenuItem [list \
  1038.       "gnuplot" \
  1039.       "(-" \
  1040.       {Menu -m -s -n "Settings" -p gnuplotMenuItem  {\
  1041.       "line styles…&" \
  1042.       "text format…&" \
  1043.       "labels…&" \
  1044.       "offsets…&" \
  1045.     }}\
  1046.     "(-" \
  1047.     "$gp_sm" \
  1048.     ]
  1049.   
  1050.   GPLT::graphButton
  1051. }
  1052.  
  1053. # ===========================================================================
  1054. #
  1055. #  Generate a new script window
  1056. #
  1057.  
  1058. proc GPLT::newWindow {} {
  1059.     set wname "Untitled.gp"
  1060.     new -n $wname -m GPLT
  1061.     GPLT::uFD
  1062.     insertText "#\r"
  1063.     setWinInfo -w $wname dirty 0
  1064. }
  1065.  
  1066. # ===========================================================================
  1067. #
  1068. #  Insert File Description---use Vince's if possible.
  1069. #      this used in creating new window and in dumping history list
  1070. #
  1071.  
  1072. proc GPLT::uFD { } {
  1073.     # catch {userFileDescription } ans
  1074.     # if {     $ans != ""    }  {
  1075.     insertText "#\r#\r#     " [join [mtime [now] long] ] "\r"
  1076.     nextLine
  1077.     #}
  1078.     endOfBuffer
  1079. }
  1080.  
  1081. # ===========================================================================
  1082. #
  1083. #  Tell gnuplot to quit
  1084. #
  1085.  
  1086. proc GPLT::quit {} {
  1087.     global gp_Console
  1088.     
  1089.     switchTo 'ALFA'
  1090.     set wins [winNames]
  1091.     if { [set winThere [lsearch $wins $gp_Console ] ] >= 0} {
  1092.     set name [lindex $wins $winThere]
  1093.     bringToFront $name
  1094.     killWindow
  1095.     }
  1096.     
  1097. }
  1098.  
  1099. # ===========================================================================
  1100. #
  1101. #  Switch to gnuplot
  1102. #
  1103.  
  1104. proc GPLT::activate {  } {
  1105.     global   GnuplotSig
  1106.     
  1107.     if { ![GPLT::check] } {
  1108.     switchTo \'$GnuplotSig\'
  1109.     }
  1110. }
  1111.  
  1112. # ===========================================================================
  1113. #
  1114. #  Filter curlyq's out of sting...We may need to be smarter
  1115. #    about this later
  1116. #
  1117.  
  1118. proc GPLT::filtercurlyq { it } {
  1119.     
  1120.     set from [string first "“" $it]
  1121.     set to [string first "”" $it]
  1122.     set ans [string range $it [expr $from + 1] [expr $to - 1] ]
  1123.     if { ![expr [string length $ans] -1 ] } {
  1124.     regexp -nocase {[a-z0-9]} $ans nans
  1125.     if {[info exists nans]} {
  1126.         set ans $nans
  1127.     } else {
  1128.         set ans ""
  1129.     }
  1130.  
  1131.     }
  1132.     
  1133.     return $ans
  1134. }
  1135.  
  1136. # ===========================================================================
  1137. #
  1138. #  Extract current gnuplot path from event reply
  1139. #
  1140.  
  1141. proc GPLT::extractPath { ans } {
  1142.     global gp_cwd
  1143.     
  1144.     # We need to be tricky since I'm not sure if Dave is sending the
  1145.     # path in an alis, or as a string
  1146.     #    regexp {“(.*)(”.*“)(.*)”} "$ans" dummy spec1 spec2 spec3
  1147.     
  1148.     set frst [ string first "PSTR:" "$ans" ]
  1149.     set lst [ string first "TERM:" "$ans" ]
  1150.     
  1151.     if { ($frst > 0) } {
  1152.     if { $lst <= 0 } { set lst [string length $ans ] }
  1153.     set ans [string range "$ans" $frst $lst ]
  1154.     regexp {“(.*)”} "$ans" dummy  spec3   spec1
  1155.     if {[info exists spec3]} {
  1156.         set ngp_cwd $spec3
  1157.         if {$ngp_cwd != "" } {
  1158.         set gp_cwd "$ngp_cwd"
  1159.         return 0
  1160.         } 
  1161.     }
  1162.     }
  1163.     
  1164.     regexp {«(.*)»} "$ans" dummy spec
  1165.     if {[info exists spec]} {
  1166.     set ngp_cwd [specToPathName $spec]
  1167.     if {$ngp_cwd != "" } {
  1168.         set gp_cwd "$ngp_cwd"
  1169.         return 0
  1170.     } 
  1171.     }
  1172. }
  1173.  
  1174. # ===========================================================================
  1175. #
  1176. #  Send a command to gnuplot and return stderr!
  1177. #
  1178.  
  1179. proc GPLT::sTDERR { mycommand tmout } {
  1180.     global  gp_cwd  GPLTmodeVars GnuplotSig gp_TYPE gp_CREA
  1181.     
  1182.     if { ! $GPLTmodeVars(EventHandler) } {
  1183.     catch { AEBuild -t $tmout -r \'$GnuplotSig\' GPSE  "exec" ---- \
  1184.       [curlyq $mycommand] {CREA:} "$gp_CREA" \
  1185.       {TYPE:} "$gp_TYPE" } ans
  1186.     } else {
  1187.     catch { AEBuild -t $tmout -r \'$GnuplotSig\' GPSE  "exec" ---- \
  1188.       [curlyq $mycommand] {CLIE:} "ALFA" {CREA:} "$gp_CREA" \
  1189.       {TYPE:} "$gp_TYPE" } ans
  1190.     }
  1191.     if { $ans == "Unable to find process"  }  GPLT::quit
  1192.     GPLT::extractPath $ans
  1193.     return [GPLT::filtercurlyq $ans]
  1194. }
  1195.  
  1196. # ===========================================================================
  1197. #
  1198. #  Save current window and execute it in GNUPLOT, just like GNUPLOT
  1199. #  command ;)
  1200. #
  1201.  
  1202. proc GPLT::saveAndExecute {} {
  1203.     
  1204.     if {[winDirty]} {save}
  1205.     
  1206.     # Get the path of the current window and it's name
  1207.     
  1208.     # Set the working directory to the current window's
  1209.     # current dir.
  1210.     set GPLTFilePath "cd \'\:"
  1211.     set GPLTFile [lindex [winNames -f] 0]
  1212.     set GPLTFP [file dirname $GPLTFile]
  1213.     append  GPLTFilePath  $GPLTFP ":\'"
  1214.     
  1215.     # use unix style file paths
  1216.     regsub -all ":" $GPLTFilePath {/} GPLTFilePath
  1217.     
  1218.     # get the load command ready...
  1219.     set scriptName  "load \'"
  1220.     append scriptName [file tail $GPLTFile] "\'"
  1221.     
  1222.     # Change current working directory to window's
  1223.     GPLT::sendCommand $GPLTFilePath 600
  1224.     
  1225.     # Do the script
  1226.     GPLT::sendCommand $scriptName 700
  1227. }
  1228.  
  1229. # ===========================================================================
  1230. #
  1231. #  Write results to command window
  1232.  
  1233. proc GPLT::results { res } {
  1234.     global gp_Console gp_cwd
  1235.     insertText -w "$gp_Console"  "\n" $res
  1236.     setWinInfo -w "$gp_Console" dirty 0
  1237.     message "Current gnuplot Path ==> $gp_cwd"
  1238. }
  1239.  
  1240. # ===========================================================================
  1241. #
  1242. #  Send line to GNUPLOT
  1243. #
  1244.  
  1245. proc GPLT::doLine {} {
  1246.     
  1247.     beginningOfLine
  1248.     set bol [getPos]
  1249.     endOfLine
  1250.     set eol [getPos]
  1251.     
  1252.     set scriptName [getText $bol $eol]
  1253.     GPLT::sendCommand $scriptName     800
  1254. }
  1255.  
  1256. # ===========================================================================
  1257. #
  1258. #  Send selection to GNUPLOT
  1259. #
  1260.  
  1261. proc GPLT::doSelection {} {
  1262.     # Break lines into separate commands.
  1263.     foreach sN [split [getSelect] "\r"] {
  1264.     GPLT::sendCommand $sN 900
  1265.     }
  1266.     
  1267. }
  1268.  
  1269. # ===========================================================================
  1270. #
  1271. #  Edit current window in GNUPLOT
  1272. #
  1273.  
  1274. proc GPLT::editFile {} {
  1275.     global GnuplotSig
  1276.     
  1277.     if { ![GPLT::check] } {
  1278.     set thisWin  [lindex [winNames] 0]
  1279.     if {[winDirty]} {
  1280.         if {[askyesno "Save '$thisWin'?"] == "yes"} {
  1281.         save
  1282.         } else {
  1283.         return
  1284.         } 
  1285.     }
  1286.     set thisWin  [lindex [winNames -f ] 0]
  1287.     killWindow
  1288.     if {![catch {sendOpenEvent -n \'$GnuplotSig\' $thisWin }]} {
  1289.         switchTo \'$GnuplotSig\' 
  1290.     }
  1291.     }
  1292. }
  1293.  
  1294. #
  1295. #  closeHook procedure so that gnuplot is quit
  1296. #  whenever the user closes the console window.  Also ask about
  1297. #  saving the history list when the console is closed.
  1298. #
  1299.  
  1300. proc GPLT::closeHook    {name} {
  1301.     global gnuplotMenu GPLTmodeVars PREFS modifiedArrayElements
  1302.     global gp_CreatorList gp_TypeList gp_Console gp_Graph gp_Hist
  1303.     global gp_CreatorNames gp_CommandNum gp_Launched GnuplotSig modifiedVars
  1304.     global gp_GEOM gp_HistGEOM modifiedVars
  1305.     
  1306.     if { [string first "$gp_Console" $name] == 0    } {
  1307.  
  1308.     if    {$gp_CommandNum != 0 && ! $GPLTmodeVars(NevrSavHist) } {
  1309.         GPLT::dumpHistory
  1310.         set ans [askyesno -c "Savegnuplot command History?" ]
  1311.     } else {    set ans "yes" }
  1312.  
  1313.     GPLT::offSet
  1314.     switch -exact [string tolower $ans] {
  1315.         "cancel"   { GPLT::console; return $result }
  1316.         "no"       { GPLT::clearHistory }
  1317.         "yes"       { 
  1318.         catch { setWinInfo -w $gp_Hist read-only 0 } jj
  1319.         catch { setWinInfo -w $gp_Hist dirty 1 } jj
  1320.         catch { bringToFront $gp_Hist } jj
  1321.         if { $jj == 0 } {
  1322.             catch { saveAs "history.gp" } jj
  1323.         }
  1324.         catch { setWinInfo -w $gp_Hist dirty 0 } jj
  1325.         catch { setWinInfo -w $gp_Hist read-only 1 } jj
  1326.         GPLT::clearHistory
  1327.         }
  1328.     }
  1329.     # end case
  1330.     #        if {$gp_Launched    !=    0 } {
  1331.     catch { sendQuitEvent \'$GnuplotSig\' } hhh
  1332.     lappend modifiedVars  GnuplotSig
  1333.     #            }
  1334.     set gp_Launched 0
  1335.     set wins [winNames]
  1336.     if { [lsearch $wins $gp_Hist  ]  >= 0} {
  1337.         bringToFront $gp_Hist
  1338.         killWindow
  1339.     }
  1340.     lappend modifiedVars   gp_GEOM
  1341.     lappend modifiedVars   gp_HistGEOM
  1342.  
  1343.     } elseif {[string first $gp_Hist    $name] == 0} {
  1344.     set wins [winNames]
  1345.     if { [lsearch $wins "$gp_Console" ]  >= 0} {
  1346.         set GPLTmodeVars(LiveHist) 0
  1347.     }
  1348.     }
  1349. }
  1350.  
  1351. # ===========================================================================
  1352. #
  1353. #  Redefine the deactivateHook procedure so that gnuplot is quit
  1354. #  whenever the user closes the console window.  Also ask about
  1355. #  saving the history list when the console is closed.
  1356. #
  1357.  
  1358. proc GPLT::deactivateHook    {name} {
  1359.     global  gp_Hist GPLTmodeVars gp_Console gp_Graph
  1360.     global  gp_GEOM gp_HistGEOM
  1361.     if    { [string first $gp_Hist $name] == 0    } {
  1362.     set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1363.     endOfBuffer
  1364.     } elseif {[string first "$gp_Console" $name] == 0} {
  1365.     set gp_GEOM [getGeometry "$gp_Console" ]
  1366.     }
  1367. }
  1368.  
  1369. # ===========================================================================
  1370. #
  1371. #  Redefine the activateHook procedure so that gnuplot is quit
  1372. #  whenever the user closes the console window.  Also ask about
  1373. #  saving the history list when the console is closed.
  1374. #
  1375.  
  1376. proc GPLT::activateHook    {name} {
  1377.     global  gp_Hist gp_Graph gp_Console modifiedArrayElements
  1378.     global  mode gp_cwd GPLTmodeVars mode gp_modflag gp_GEOM
  1379.     
  1380.     if    { [string first "$gp_Console" $name] == 0} {
  1381.     changeMode GPLT
  1382.     set gp_GEOM [ getGeometry "$gp_Console" ]
  1383.     } elseif    { [string first $gp_Hist $name] == 0} {
  1384.     set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1385.     }
  1386.     
  1387.     message "Current gnuplot Path ==> $gp_cwd"
  1388. }
  1389.  
  1390. # ===========================================================================
  1391. #
  1392. # ◊◊◊◊ Command History ◊◊◊◊ #
  1393.  
  1394. # ===========================================================================
  1395. #
  1396. #  History goto match...
  1397. #
  1398.  
  1399. proc GPLT::histgotoMatch {} {
  1400.     set frst [lineStart [getPos] ]
  1401.     endOfLine
  1402.     set lst  [getPos]
  1403.     endOfBuffer
  1404.     beginningOfLine
  1405.     GPLT::sendCommand [getText $frst $lst ] 1000
  1406. }
  1407.  
  1408. # ===========================================================================
  1409. #
  1410. #  Display or rewrite "command" to command window
  1411. #  
  1412.  
  1413. proc GPLT::dispCommand {command} {
  1414.     global   gp_Prompts gp_cwd
  1415.     
  1416.     # This is ugly and probably not very efficient.
  1417.     
  1418.     set lst [maxPos]
  1419.     set boll [lineStart $lst]
  1420.     set curr [getPos]
  1421.     
  1422.     if {[pos::compare $curr >= $boll]} {   
  1423.     set bol [lineStart $curr]
  1424.     set eol [nextLineStart $curr]
  1425.     set text [getText $bol $eol]
  1426.     set ltext [getText $boll $lst]
  1427.     foreach gp $gp_Prompts {
  1428.         set c1 [string first $gp $ltext]
  1429.         set c2 [pos::diff $lst $boll]
  1430.         set c3 [string length $gp]
  1431.         set c4 [pos::diff $lst $curr]
  1432.         set c5 [string length $command]
  1433.         if { $c1 == 0 && [expr $c2 >= $c3 | $c4 >= $c5 ] } {
  1434.         if {[string first $command $text] == -1} {
  1435.             set a [pos::math $boll + [string length $gp] ]
  1436.             set b [string trim $command "\r\n"]
  1437.             replaceText $lst $a $b
  1438.         }
  1439.         }
  1440.     }
  1441.     }
  1442. }
  1443.  
  1444. # ===========================================================================
  1445. #
  1446. #  Add command to history list
  1447. #
  1448.  
  1449. proc GPLT::addToHist  { cmmd } {
  1450.     global gp_CommandHist gp_CommandNum gnuplotMenu
  1451.     global GPLT::console gp_Hist GPLTmodeVars
  1452.     
  1453.     enableMenuItem gnuplotOptions "clearHistory" on
  1454.     lappend gp_CommandHist $cmmd
  1455.     set gp_CommandNum [llength $gp_CommandHist]
  1456.     
  1457.     if { $GPLTmodeVars(LiveHist) } {
  1458.     # if history list active then append $cmmd on last line
  1459.     set wins [winNames]
  1460.     if { [lsearch $wins $gp_Hist ]  >= 0} {
  1461.         setWinInfo -w $gp_Hist dirty 1
  1462.         setWinInfo -w $gp_Hist  read-only 0
  1463.         insertText -w $gp_Hist "$cmmd\r"
  1464.         setWinInfo -w $gp_Hist  dirty 0
  1465.         setWinInfo    -w $gp_Hist  read-only 1
  1466.     } else {
  1467.         GPLT::dumpHistory
  1468.         bringToFront "$gp_Console"
  1469.     }
  1470.  
  1471.     }
  1472. }
  1473.  
  1474. # ===========================================================================
  1475. #
  1476. #  Clear History list
  1477. #
  1478.  
  1479. proc GPLT::clearHistory {} {
  1480.     global  gnuplotMenu gp_CommandHist gp_CommandNum  gp_Hist
  1481.     
  1482.     set gp_CommandHist [list]
  1483.     set gp_CommandNum "0"
  1484.     enableMenuItem gnuplotOptions "clearHistory" off
  1485.     set wins [winNames]
  1486.     if { [lsearch $wins $gp_Hist ] >= 0} {
  1487.     bringToFront $gp_Hist
  1488.     killWindow
  1489.     }
  1490. }
  1491.  
  1492. # ===========================================================================
  1493. #
  1494. #  Write History list into a window of its own.
  1495. #
  1496.  
  1497. proc GPLT::dumpHistory {} {
  1498.     global gp_CommandHist gp_CommandNum gp_Console
  1499.     global GPLTmodeVars gp_Console gp_Hist
  1500.     global gp_GEOM
  1501.     
  1502.     set wins [winNames]
  1503.     set nw [ llength $wins ]
  1504.     
  1505.     if { [lsearch $wins $gp_Hist ]  == -1} {
  1506.     set l [ expr [lindex $gp_GEOM 0] + 12 + [lindex $gp_GEOM 2] ]
  1507.     set t [ expr [lindex $gp_GEOM 1] + 65 ]
  1508.     set w 96
  1509.     set h [ expr [lindex $gp_GEOM 3] - 65 ]
  1510.     new -n $gp_Hist -g $l $t $w $h -m GPLT
  1511.     set gp_HistGEOM [getGeometry]
  1512.     GPLT::uFD
  1513.     set scriptName "# (<cr> to send to gnuplot)\r#-----\r"
  1514.     foreach word $gp_CommandHist  {append  scriptName  $word "\r" }
  1515.     insertText  -w $gp_Hist $scriptName
  1516.     setWinInfo dirty 0
  1517.     setWinInfo read-only 1
  1518.     } else {
  1519.     bringToFront $gp_Hist
  1520.     }
  1521. }
  1522.  
  1523. # ===========================================================================
  1524. #
  1525. # Navigation
  1526.  
  1527. proc GPLT::prevCommand {} {
  1528.     global  gp_CommandHist gp_CommandNum gp_Hist gp_Prompt gp_MultiPrompt
  1529.     global  gp_ContPrompt gp_Console gp_Hist
  1530.     
  1531.     # enter only if cr in console window...
  1532.     set wins [winNames]
  1533.     if { [lsearch $wins "$gp_Console" ] == 0} {
  1534.  
  1535.     set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ] ]
  1536.     if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1537.         goto [pos::math [lineStart [getPos] ] + $ind + [string length $gp_Prompt] ]
  1538.     } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1539.         goto [pos::math [lineStart [getPos] ] + $ind +
  1540.         [string length $gp_Multiprompt] ]
  1541.     } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1542.         goto [pos::math [lineStart [getPos] ] + $ind + [string length $gp_Contprompt] ]
  1543.     } elseif { return }
  1544.  
  1545.     incr gp_CommandNum -1
  1546.     if {$gp_CommandNum < 0} {
  1547.         incr gp_CommandNum
  1548.         endOfLine
  1549.         return
  1550.     }
  1551.     set text [lindex $gp_CommandHist $gp_CommandNum]
  1552.     set to [nextLineStart [getPos] ]
  1553.     if {[lookAt [pos::math $to -1] ] == "\r"} {set to [pos::math $to -1]}
  1554.  
  1555.     replaceText [getPos] $to $text
  1556.     } elseif { [lsearch $wins $gp_Hist ]  == 0} {
  1557.  
  1558.     set limit [nextLineStart [nextLineStart [minPos]] ]
  1559.     if {[pos::compare [getPos] > $limit]} {
  1560.         set limit [pos::math [getPos] - 1]
  1561.     }
  1562.     select [lineStart $limit] [nextLineStart $limit]
  1563.     } else {
  1564.     previousLine
  1565.     }
  1566.     
  1567. }
  1568.  
  1569. proc GPLT::nextCommand {} {
  1570.     global  gp_CommandHist gp_CommandNum gp_Prompt gp_MultiPrompt
  1571.     global gp_ContPrompt gp_Console gp_Hist
  1572.     
  1573.     # enter only if cr in console window...
  1574.     set wins [winNames]
  1575.     if { [lsearch $wins "$gp_Console"  ]  == 0} {
  1576.  
  1577.     set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ]]
  1578.     if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1579.         goto [pos::math [lineStart [getPos] ] + $ind + 9]
  1580.     } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1581.         goto [pos::math [lineStart [getPos] ] + $ind + 11]
  1582.     } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1583.         goto [pos::math [lineStart [getPos] ] + $ind + 3]
  1584.     } else  {
  1585.         endOfBuffer
  1586.         return
  1587.     }
  1588.  
  1589.     incr gp_CommandNum
  1590.     if {$gp_CommandNum > [llength $gp_CommandHist]} {
  1591.         incr gp_CommandNum -1
  1592.         return
  1593.     }
  1594.     set text [lindex $gp_CommandHist $gp_CommandNum]
  1595.     set to [nextLineStart [getPos] ]
  1596.     if {[lookAt [pos::math $to -1] ] == "\r"} {set to [pos::math $to -1]}
  1597.     replaceText [getPos] $to $text
  1598.     } elseif { [lsearch $wins $gp_Hist  ]  == 0} {
  1599.     set pos [getPos]
  1600.     if {[pos::compare $pos < [nextLineStart [minPos]]]} {
  1601.         set pos [nextLineStart [minPos]]
  1602.     }
  1603.     if {[pos::compare [nextLineStart $pos] != [maxPos]]} {
  1604.         select [nextLineStart $pos] [nextLineStart [nextLineStart $pos] ]
  1605.     }
  1606.     } else {
  1607.     # mv cusor down...
  1608.     nextLine
  1609.     }
  1610. }
  1611.  
  1612. # ===========================================================================
  1613. # ◊◊◊◊ Additional Menu Support ◊◊◊◊ #
  1614.  
  1615. # ===========================================================================
  1616. #
  1617. #  change behavior of modifyModeFlags
  1618. #
  1619.  
  1620. proc GPLT::modifyModeFlags {{title ""}} {
  1621.     global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  1622.     global gnuplotMenu  gp_Graph gp_Console  gp_Hist gp_floatmenu
  1623.     
  1624.     set wins [winNames]
  1625.     if { [lsearch $wins "$gp_Console" ]  >= 0}  {
  1626.     set gp_GEOM [ getGeometry "$gp_Console" ]
  1627.     }
  1628.     
  1629.     if { [lsearch $wins $gp_Hist] >= 0 } {
  1630.     set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1631.     }
  1632.     
  1633.     set gp_modflag 1
  1634.     
  1635.     if { $GPLTmodeVars(LiveHist) } {
  1636.     set wins [winNames]
  1637.     if { [lsearch $wins "$gp_Console"  ]  >= 0} {
  1638.         GPLT::dumpHistory
  1639.     }
  1640.     } else {
  1641.     set wins [winNames]
  1642.     if {[lsearch $wins $gp_Hist  ]  >= 0} {
  1643.         bringToFront $gp_Hist
  1644.         killWindow
  1645.     }
  1646.     }
  1647.     if { $GPLTmodeVars(EventHandler) } {
  1648.     } else {
  1649.     set jj1 "The event handler is broken in Alpha (68k).
  1650.     set jj2 "You may need to disable event handling until it is fixed."
  1651.     alertnote $jj1 $jj2
  1652.     }
  1653.     if { $GPLTmodeVars(GraphButton) } {
  1654.     GPLT::graphButton
  1655.     } else {
  1656.     GPLT::killGraphButton
  1657.     }
  1658.     # This file is sourced when appropriate by Alpha,
  1659.     # it should not happen here.
  1660.     # catch {  source $PREFS:GPLTPrefs.tcl } jjj
  1661.     catch {    bringToFront "$gp_Console" } jjj
  1662. }
  1663.  
  1664. # ===========================================================================
  1665. #
  1666. #  Select creator from list
  1667. #
  1668.  
  1669. proc GPLT::selectCreator {} {
  1670.     global gp_CreatorNames  gp_CreatorList   gp_TypeList GPLTmodeVars
  1671.     global setOutputCreator modifiedArrayElements modifiedVars
  1672.     global gp_CREA gp_TYPE
  1673.     
  1674.     set crea [listpick -p "Select output file creator:" $gp_CreatorNames  ]
  1675.     set creator [lindex $gp_CreatorList [lsearch  $gp_CreatorNames $crea] ]
  1676.     set type [lindex $gp_TypeList [lsearch  $gp_CreatorNames $crea] ]
  1677.     if {$creator == {} } {
  1678.     set gp_CREA 'ALFA'
  1679.     set gp_TYPE 'TEXT'
  1680.     } else {
  1681.     set gp_CREA $creator
  1682.     set gp_TYPE $type
  1683.     }
  1684.     lappend modifiedVars  gp_TYPE
  1685.     lappend modifiedVars  gp_CREA
  1686.     lappend modifiedVars  gp_CreatorList
  1687.     lappend modifiedVars  gp_TypeList
  1688.     lappend modifiedVars  gp_CreatorNames
  1689. }
  1690.  
  1691. # ===========================================================================
  1692. #
  1693. #  Add creator to list from file dialog
  1694. #
  1695.  
  1696. proc GPLT::addCreator {} {
  1697.     global gp_CreatorNames  gp_CreatorList  gnuplotMenu gp_TypeList
  1698.     global GPLTmodeVars modifiedVars modifiedArrayElements
  1699.     global gp_CREA gp_TYPE
  1700.     
  1701.     set fname [getfile "Select file type for creator"]
  1702.     #  add to creator list
  1703.     if {[getFileType $fname]=="APPL"} {
  1704.     alertnote "Sorry, but that was an application. \rTry again."
  1705.     return
  1706.     }
  1707.     
  1708.     if {$fname != {}} {
  1709.     set nm [getline "What do you wish to call it?" [file tail $fname ] ]
  1710.     if {$nm != {} } {
  1711.         set gp_CREA  [getFileSig $fname]
  1712.         set gp_TYPE  [getFileType $fname]
  1713.         lappend gp_CreatorList  $gp_CREA
  1714.         lappend gp_TypeList     $gp_TYPE
  1715.         lappend gp_CreatorNames $nm
  1716.         enableMenuItem  setOutputCreator "Select…" on
  1717.         enableMenuItem  setOutputCreator "Delete…" on
  1718.         lappend modifiedVars  gp_TYPE
  1719.         lappend modifiedVars  gp_CREA
  1720.         lappend modifiedVars  gp_CreatorList
  1721.         lappend modifiedVars  gp_TypeList
  1722.         lappend modifiedVars  gp_CreatorNames
  1723.     }
  1724.     }
  1725.     
  1726.     
  1727. }
  1728.  
  1729. # ===========================================================================
  1730. #
  1731. #  Remove creator from list
  1732. #
  1733.  
  1734. proc GPLT::deleteCreator {} {
  1735.     global gp_CreatorNames gnuplotMenu gp_CreatorList  gp_TypeList
  1736.     global GPLTmodeVars modifiedVars modifiedArrayElements
  1737.     global gp_CREA gp_TYPE
  1738.     
  1739.     set crea [listpick -p "Select creator to be deleted:"  $gp_CreatorNames ]
  1740.     
  1741.     if {$crea != {}} {
  1742.     #  now remove this creator from both lists....
  1743.     set creatorInd [lsearch  $gp_CreatorNames $crea]
  1744.     set crea [ lindex $gp_CreatorList $creatorInd]
  1745.     set gp_CreatorNames [ lreplace $gp_CreatorNames $creatorInd $creatorInd ]
  1746.     set gp_CreatorList  [ lreplace $gp_CreatorList  $creatorInd $creatorInd ]
  1747.     set gp_TypeList     [ lreplace $gp_TypeList     $creatorInd $creatorInd ]
  1748.  
  1749.     if {$gp_CREA == $crea } {
  1750.         set gp_CREA 'ALFA'
  1751.         set gp_TYPE 'TEXT'
  1752.     }
  1753.     lappend modifiedVars  gp_TYPE
  1754.     lappend modifiedVars  gp_CREA
  1755.     lappend modifiedVars  gp_CreatorList
  1756.     lappend modifiedVars  gp_TypeList
  1757.     lappend modifiedVars  gp_CreatorNames
  1758.     }
  1759.     
  1760.     if {[llength $gp_CreatorList] == 0} {
  1761.     enableMenuItem  setOutputCreator "Select…" off
  1762.     enableMenuItem setOutputCreator "Delete…" off
  1763.     }
  1764. }
  1765.  
  1766. # ===========================================================================
  1767. #
  1768. #  Clear a few globals...
  1769. #
  1770.  
  1771. proc GPLT::clear {} {
  1772.     global PREFS  GPLTmodeVars
  1773.     global  gp_CreatorList gp_CreatorNames
  1774.     global gp_GEOM gp_HistGEOM modifiedVars
  1775.     global gp_CREA gp_TYPE
  1776.     
  1777.     if { [info exists gp_GEOM] } { set gp_GEOM [list] }
  1778.     if { [info exists gp_CreatorList] } { unset gp_CreatorList }
  1779.     if { [info exists gp_TypeList] } { unset gp_TypeList }
  1780.     if { [info exists gp_CreatorNames] } { unset gp_CreatorNames }
  1781.     if { [info exists gp_HistGEOM] } { unset gp_HistGEOM  }
  1782.     if { [info exists gp_CREA] } { unset gp_CREA  }
  1783.     if { [info exists gp_TYPE] } { unset gp_TYPE  }
  1784.     
  1785.     ensureset gp_CreatorList [list ALFA GPLT ]
  1786.     ensureset gp_TypeList [list TEXT TEXT ]
  1787.     ensureset gp_CreatorNames [list alpha gnuplot]
  1788.     ensureset gp_CREA ALFA
  1789.     ensureset gp_TYPE TEXT
  1790.     ensureset gp_GEOM [list]
  1791.     ensureset gp_HistGEOM [list ]
  1792.     
  1793.     if { [llength $gp_CreatorList] == 0 \
  1794.       || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  1795.       || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  1796.     set gp_CreatorList [list]
  1797.     set gp_TypeList [list]
  1798.     set gp_CreatorNames [list]
  1799.     }
  1800.     
  1801.     lappend modifiedVars gp_CreatorNames gp_TypeList gp_CreatorList
  1802.     lappend modifiedVars gp_HistGEOM gp_GEOM
  1803.     lappend modifiedVars gp_TYPE gp_CREA
  1804.     # catch { source $PREFS:gnuplotMode.tcl } blah
  1805.     # catch { source $HOME:Tcl:Modes:gnuplotMode.tcl } blah
  1806. }
  1807.  
  1808. # ===========================================================================
  1809. #
  1810. #  run load scripts from scripts menu
  1811. #
  1812.  
  1813. proc GPLT::scriptMenuItems {menu item} {
  1814.     global gp_sl gp_home gp_scriptItems gp_Path  gp_openItems
  1815.     
  1816.     set men [string tolower $menu]
  1817.     set ite [string tolower $item]
  1818.     
  1819.     if { "$item" == "Rebuild Menu" } {
  1820.     set cdir [pwd]
  1821.     set sl [expr [string length $gp_Path ] - 2]
  1822.     cd [string range $gp_Path 0 $sl ]
  1823.     GPLT::rebuildScriptMenu
  1824.     cd "$cdir"
  1825.     return 0
  1826.     }
  1827.     
  1828.     foreach it $gp_scriptItems {
  1829.     if { [string match "cd \'*$men:\'; load \'*$men:$ite\'" [string tolower $it] ] } {
  1830.         GPLT::sendCommand "$it" 110
  1831.         return 0
  1832.     }  
  1833.     }
  1834.     
  1835.     # set men [string tolower [string range $menu 5 [string length $menu] ] ]
  1836.     
  1837.     # filter out the "• edit "  from the selected $menu $item
  1838.     set ite [string tolower [string range $item 7 [string length $item] ] ]
  1839.     
  1840.     foreach it $gp_openItems {
  1841.     if { [string match "*$men:$ite" [string tolower $it] ] } {
  1842.         edit "$it"
  1843.         changeMode GPLT
  1844.         return 0
  1845.     }  
  1846.     }
  1847. }
  1848.  
  1849. # ===========================================================================
  1850. #
  1851. #  Create floating menu
  1852. #
  1853.  
  1854. set GPLT::graphMenu "gnuplotGraph"
  1855.  
  1856. set gp_grmen [list "Menu  -n ${GPLT::graphMenu} -p gnuplotMenuItem" ]
  1857. lappend gp_grmen "gnuplot" "(-"
  1858.  
  1859. Menu -n ${GPLT::graphMenu} -p gnuplotMenuItem [concat "gnuplot"]
  1860.  
  1861. # ===========================================================================
  1862. #
  1863. #  Create a floating gnuplot graph button (Alpha 6.2 or higher)
  1864. #
  1865.  
  1866. proc GPLT::graphButton {{addButton "0"}} {
  1867.     global gp_floatmenu GPLT::graphMenu GPLTmodeVars 
  1868.     global gp_sl gp_Path gp_GEOM gp_FLTGEOM
  1869.     
  1870.     #    if {[llength $gp_FLTGEOM] != 2 } {
  1871.     if {[llength $gp_GEOM] == 4 } {
  1872.     set l [ expr [lindex $gp_GEOM 0] + 5 + [lindex $gp_GEOM 2] ]
  1873.     set t [ expr [lindex $gp_GEOM 1] - 20 ]
  1874.     set gp_FLTGEOM [list $l $t ]
  1875.     } else {
  1876.     set l 20
  1877.     set t 20
  1878.     }
  1879.     #    }  else {
  1880.     #          set l  [lindex $gp_FLTGEOM 0]
  1881.     #          set t  [lindex $gp_FLTGEOM 1]
  1882.     #    }
  1883.     
  1884.     if {$GPLTmodeVars(GraphButton) || $addButton} {
  1885.     if {[info exists gp_floatmenu]} {
  1886.         GPLT::killGraphButton
  1887.     }
  1888.     catch {
  1889.         set gp_floatmenu [float -m ${GPLT::graphMenu} -n "" -M -1 -z GPLT -l $l -t $t ]
  1890.     }
  1891.     }
  1892. }
  1893.  
  1894. # Call this now.
  1895.  
  1896. GPLT::graphButton
  1897.  
  1898. # ===========================================================================
  1899. #
  1900. #  Kill a floating gnuplot menu (Alpha 6.2 or higher)
  1901. #
  1902.  
  1903. proc GPLT::killGraphButton {} {
  1904.     global gp_floatmenu
  1905.     
  1906.     if {[info exists  gp_floatmenu]}  {
  1907.     catch {unfloat ${gp_floatmenu}}
  1908.     unset gp_floatmenu
  1909.     }
  1910. }
  1911.  
  1912. # ===========================================================================
  1913. #
  1914. #  Generate the script menu
  1915. #
  1916.  
  1917. proc GPLT::scriptList { sdir men } {
  1918.     global gp_scriptItems  gp_openItems
  1919.     
  1920.     if {"$men" == "Scripts" } {
  1921.     set sl [list "\(Rebuild Menu"]
  1922.     } else {
  1923.     set sl [list]
  1924.     }
  1925.     
  1926.     # get the list of text files in $sdir
  1927.     set gp_fl [ glob -nocomplain -types TEXT "$sdir"]
  1928.     set mdir [string range "$sdir" 0 [expr [string length "$sdir"] - 2 ] ]
  1929.     set rdir [string range "$mdir" 0 [expr [string length "$mdir"] -1 ] ]
  1930.     foreach f $gp_fl {
  1931.     set mitem [string range $f [expr 1 + [string last ":" "$f" ] ] [ string length "$f" ] ]
  1932.     # append mitem "&"
  1933.     if { $mitem != "" } {
  1934.         lappend sl "<E<S$mitem"
  1935.         lappend sl "<S<I• edit $mitem"
  1936.         lappend sl "<S<B• edit $mitem"
  1937.         lappend sl "<S<U• edit $mitem"
  1938.         lappend sl "<S<O• edit $mitem"
  1939.         lappend gp_scriptItems "cd \'$rdir\'; load \'$f\'"
  1940.         lappend gp_openItems "$f"
  1941.     }
  1942.     }
  1943.     
  1944.     # get the list of aliased directories in $sdir and
  1945.     # perform this operation again on subdirectories
  1946.     set dlist [ glob   -types fdrp -nocomplain "$sdir"]
  1947.     foreach d $dlist {
  1948.     set dn [string range $d [expr [string last ":" "$d" ] +1 ] [string length $d]   ]
  1949.     # set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  1950.     set sl [concat "$sl"  [concat " \{Menu -m -n" "\"$dn\"" -p GPLT::scriptMenuItems  " \{  "  ] ]
  1951.     set dnam $d
  1952.     append dnam "*"
  1953.     # set gp_ssl [ GPLT::scriptList "$dnam" $dn ]
  1954.     set gp_ssl [list "(ALIASED FOLDERS NOT WORKING YET"]
  1955.     set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  1956.     }
  1957.     
  1958.     # get the list of directories in $sdir and
  1959.     # perform this operation again on subdirectories
  1960.     set dlist [ glob -nocomplain  "$sdir:"]
  1961.     foreach d $dlist {
  1962.     set dn [string range $d 0 [expr [string last ":" "$d" ] - 1 ]  ]
  1963.     set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  1964.     set sl [concat "$sl"  [concat " \{Menu -m -n" "\"$dn\"" -p GPLT::scriptMenuItems  " \{  "  ] ]
  1965.     set dnam $d
  1966.     append dnam "*"
  1967.     set gp_ssl [ GPLT::scriptList "$dnam" $dn ]
  1968.     set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  1969.     }
  1970.     
  1971.     return  $sl
  1972. }
  1973.  
  1974. # ===========================================================================
  1975. #
  1976. #  Load a script into gnuplot
  1977. #
  1978.  
  1979. proc GPLT::loadScript {} {
  1980.     global gp_cwd
  1981.     catch { cd "$gp_cwd" } hmm
  1982.     set GPLTFile [ getfile "Choose a script to load:" ]
  1983.     if { $GPLTFile != "" } {
  1984.     GPLT::sendCommand  "load \'$GPLTFile\'" 120
  1985.     }
  1986. }
  1987.  
  1988. # ===========================================================================
  1989. #
  1990. #  Tell gnuplot to save settings...
  1991. #
  1992.  
  1993. proc GPLT::saveSettings { what } {
  1994.     global  GPLTmodeVars gp_cwd gp_TYPE gp_CREA
  1995.     
  1996.     catch { cd "$gp_cwd" } hmm
  1997.     set tCREA $gp_CREA
  1998.     set tTYPE $gp_TYPE
  1999.     set gp_CREA {ALFA}
  2000.     set gp_TYPE {TEXT}
  2001.     set where [ putfile "Save current gnuplot settings" \
  2002.       [format "gnuplot%src.gp" [string toupper $what ] ] ]
  2003.     if { $where != "" } {
  2004.     GPLT::sendCommand "save $what \'$where\'" 130
  2005.     }
  2006.     set gp_CREA  $tCREA
  2007.     set gp_TYPE  $tTYPE
  2008. }
  2009.  
  2010. # ===========================================================================
  2011. #
  2012. #  Tell gnuplot where the current dir is...
  2013. #
  2014.  
  2015. proc GPLT::setCWD {} {
  2016.     set gp_cwd [ get_directory -p "Select gnuplot working folder"]
  2017.     if { $gp_cwd != "" } {
  2018.     GPLT::sendCommand "cd \'$gp_cwd\'" 140
  2019.     }
  2020. }
  2021.  
  2022. # ===========================================================================
  2023. #
  2024. #  Tell gnuplot to change the point size
  2025. #
  2026.  
  2027. proc GPLT::setPTSZ {} {
  2028.     GPLT::sendCommand " set pointsize [ getline "Enter point size" 1 ] " 150
  2029. }
  2030.  
  2031. # ===========================================================================
  2032. #
  2033. #  Choose a file to plot and write "plot 'filename'" on command line
  2034. #
  2035.  
  2036. proc GPLT::choosePlotFile { } {
  2037.     global gp_Console gp_cwd
  2038.     catch { cd "$gp_cwd" } hmm
  2039.     set plotfile [ getPathName "Choose a file to plot" 1 ]
  2040.     if { $plotfile != "" } {
  2041.     insertText -w "$gp_Console" "plot \'$plotfile\' "
  2042.     }
  2043. }
  2044.  
  2045. # ===========================================================================
  2046. #
  2047. #  Setup menu flags, etc ... assuming gnuplot is off
  2048. #
  2049.  
  2050. proc GPLT::offSet {} {
  2051.     global gnuplotMenu gp_CreatorList
  2052.     
  2053.     enableMenuItem gnuplotOptions "clearHistory" off
  2054.     enableMenuItem $gnuplotMenu "quit gnuplot" off
  2055.     enableMenuItem $gnuplotMenu "graph" off
  2056.     enableMenuItem $gnuplotMenu "history" off
  2057.     enableMenuItem $gnuplotMenu "saveSettings" off
  2058.     enableMenuItem gnuplotOptions "setPointSize…" off
  2059.     enableMenuItem $gnuplotMenu "setWorkingFolder…" off
  2060.     enableMenuItem $gnuplotMenu "choosePlotFile…"     off
  2061.     
  2062.     if {[llength $gp_CreatorList] == 0} {
  2063.     enableMenuItem  setOutputCreator "Select…" off
  2064.     enableMenuItem  setOutputCreator "Delete…" off
  2065.     }
  2066.     
  2067. }
  2068.  
  2069. # ===========================================================================
  2070. #
  2071. #  TEMPORARY JUNK
  2072. #
  2073.  
  2074. set gp_cwd "???"
  2075.  
  2076. proc aevt { hmm } {
  2077.     # dummy procedure to fool 68k into semi-working w/eventHandler....
  2078.     if { $hmm == "'GPLT::a'()" } {
  2079.     GPLT::activate
  2080.     } elseif {$hmm=="'GPLT::c'()" } {
  2081.     GPLT::results "gnuplot> "
  2082.  
  2083.     }
  2084. }
  2085.  
  2086. # ===========================================================================
  2087. #
  2088. #  Things to do in order to properly setup gnuplot mode menu
  2089. #
  2090.  
  2091. set gp_modflag 0
  2092. GPLT::offSet
  2093.  
  2094. set gp_fm_first 1
  2095.  
  2096. # ===========================================================================
  2097. #
  2098. #  Called from menu to handle dialogs in the server app
  2099. #
  2100.  
  2101. proc GPLT::dialog { ans } {
  2102.     global  GnuplotSig
  2103.     switchTo  \'$GnuplotSig\'
  2104.     AEBuild -t 3600 -r 'GPSE' GPLT "DIAG" ---- $ans
  2105.     switchTo 'ALFA'
  2106. }
  2107.  
  2108. # ===========================================================================
  2109. #
  2110. # ◊◊◊◊ Version History ◊◊◊◊ #
  2111. #
  2112. #       =======================================================
  2113. # 0.1        8/1/95
  2114. # -----------------------------------------------
  2115. # Converted matlab.tcl to gnuplot.tcl
  2116. #
  2117. # 0.2        8/2/95
  2118. # -----------------------------------------------
  2119. # Added a "Switch to gnuplot" menu option
  2120. # Added Console modeVar                                    
  2121. # Added run in background modeVar            
  2122. # Command History mostly working in console.
  2123. # Cleaned things up a bit.
  2124. #
  2125. # 0.3        8/3/95
  2126. # -----------------------------------------------
  2127. # Console position remembered between sessions
  2128. #
  2129. # Enabled command history to be dumped to a window
  2130. # 0.4        8/3/95
  2131. # -----------------------------------------------
  2132. # User specified colorizing through check pop-up menu in GNUc console.
  2133. #     You must quit alpha and restart to see the effects.  Also, you must
  2134. #     make sure that keywords and colors don't overlap.
  2135. #
  2136. # 1.0.1        8/8/95
  2137. # -----------------------------------------------
  2138. # Handles multiplot mode
  2139. # set output file CREATOR modeVar    (not yet)
  2140. #
  2141. # 1.0.2        8/11/95
  2142. # -----------------------------------------------
  2143. # When console window is closed the gnuplot app is quit and user
  2144. #     is prompted to save the Alpha/gnuplot history
  2145. #
  2146. # Command-Dbl-Click anywhere between gnuplot prompts to select gnuplot output.
  2147. #     Nice if you send term output to the console.
  2148. #
  2149. # 1.0.3        8/12/95
  2150. # -----------------------------------------------
  2151. # Fixed bugs in closing console window
  2152. # Added wristwatch cursor while waiting for gnuplot
  2153. #
  2154. # 1.0.4        8/12/95
  2155. # -----------------------------------------------
  2156. # New modeVar to keep console "clean" 
  2157. #
  2158. # 1.0.5        8/16/95
  2159. # -----------------------------------------------
  2160. # Replaced 'dosc' w/AEBuild
  2161. # Added eventHandler  (thanks Dave)
  2162. # Dumped "clean" window since Pete will add this functionality to "new" in 6.0.2
  2163. #
  2164. # 1.0.6        8/17/95
  2165. # -----------------------------------------------
  2166. # Cleaned up several procs
  2167. # Quit now works properly
  2168. #
  2169. # 1.0        8/7/95
  2170. # -----------------------------------------------
  2171. # Now works with 3.6 (but not with 3.5)
  2172. #       ============= Above were really beta's ====================
  2173. #
  2174. # 1.0        8/21/95  (these release numbers are backwards)
  2175. # -----------------------------------------------
  2176. # First working release     
  2177. #
  2178. # 1.1        8/22/95
  2179. # -----------------------------------------------
  2180. # Set output creators from gnuplot menu
  2181. # Quit Working properly once again
  2182. # Added ERRP eventHandler for those w/o the
  2183. # Thread Manager
  2184. #
  2185. # 1.2        8/23/95
  2186. # -----------------------------------------------
  2187. # Deal w/"pause -1"     properly
  2188. # cmd-dbl-click now works for all prompts
  2189. # Cleaned up set output creator
  2190. #
  2191. # 1.2.1        8/23/95
  2192. # -----------------------------------------------
  2193. # Now works with unthreaded 68k systems
  2194. # DoSelection works for multiple lines
  2195. #
  2196. # 1.2.2        8/23/95
  2197. # -----------------------------------------------
  2198. # Repaired help/prompting/etc which broke in
  2199. # 1.2.3        8/27/95
  2200. # -----------------------------------------------
  2201. # Fixed a few prompt related items.
  2202. # I need to clean up the code a bit especially in the console output routines
  2203. #
  2204. # 1.2.4        8/28/95
  2205. # -----------------------------------------------
  2206. # I honestly don't recall
  2207. #
  2208. # 1.2.5        8/29/95
  2209. # -----------------------------------------------
  2210. # File type as well as creator settings in place
  2211. #
  2212. # 1.3        12/09/95                                                   
  2213. # -----------------------------------------------
  2214. # Should work with gnuplot app and
  2215. # Fixed an "unknown" bug---thanks Vince
  2216. # Files with gnuplot creator open in gnuplot mode
  2217. # Added several eventHandler's to work with the
  2218. # gnuplot's new personality module
  2219. # NOTE:  No longer supports the gnuplot server app, but I might add it
  2220. #     back in later...
  2221. #
  2222. # 1.3.1        12/14/95                                                   
  2223. # -----------------------------------------------
  2224. # Consolidated console and script editor modes.
  2225. # Supports server once again.   
  2226. # History dump working.......
  2227. #
  2228. # 1.3.2        12/15/95                                                   
  2229. # -----------------------------------------------
  2230. # History dump Really working this time.......
  2231. # Included a kludge eventHander: GPIC EXEC for Dave (temporary)
  2232. #
  2233. # 1.3.3        12/20/95                                                   
  2234. # -----------------------------------------------
  2235. # Added Live History window  
  2236. # Added a function sub-menu
  2237. #             
  2238. # 1.3.4        02/01/96                                                   
  2239. # -----------------------------------------------
  2240. # Added "iconic" graph window which switches to the gnuplot application
  2241. # Added a "gnuplot prefs" submenu
  2242. #
  2243. # 1.3.5        02/01/96                                                   
  2244. # -----------------------------------------------
  2245. # Some minor fixes to console routines
  2246. #  
  2247. # 1.3.6        02/26/96                                                   
  2248. # -----------------------------------------------
  2249. # Added graph button preference and repaired my broken closeHook procedure
  2250. #  
  2251. # 1.3.7        03/13/96                                                   
  2252. # -----------------------------------------------
  2253. # Added support for cwd display on message bar
  2254. #             
  2255. # 1.3.8        03/13/96                                                   
  2256. # -----------------------------------------------
  2257. # Re-arranged some code.  
  2258. #             
  2259. # 1.3.9        04/10/96                                                   
  2260. # -----------------------------------------------
  2261. # Keyword coloring editable from gnuplot pref menu.
  2262. # Gnuplot pref menu re-arranged
  2263. # This package should display the path on the message bar
  2264. #  
  2265. # 1.4.0        04/14/96                                                   
  2266. # -----------------------------------------------
  2267. # GPLT mode preferences accessable from
  2268. # config:currentmode:flags... menu
  2269. # Keyword coloring now works and is auto-sourced whenever GPTLPrefs.tcl is closed
  2270. # Reorganized and added to gnuplot menu
  2271. # Reorganized all mode specifice procedures and variable names
  2272. #  
  2273. # 1.4.1        04/15/96                                                   
  2274. # -----------------------------------------------
  2275. # Repaired broken quit and switchto menu options
  2276. #  
  2277. # 1.4.2        04/17/96
  2278. # -----------------------------------------------
  2279. # Let alpha do bookkeeping on globals
  2280. #  
  2281. # 1.4.3        04/24/96
  2282. # -----------------------------------------------
  2283. # Add trap for broken eventhandler on 68k
  2284. #  
  2285. # 1.4.4        04/26/96
  2286. # -----------------------------------------------
  2287. # Modify trap for broken eventhandler on 68k so that pause works correctly
  2288. #     and so that gnuplot can bring itself to the front
  2289. #  
  2290. # 1.5b1        07/02/96
  2291. # -----------------------------------------------
  2292. # Modify code so that it is compliant with the new mode conventions 
  2293. #     Pete added to 6.2 (see changes file).
  2294. # This script should still work for Alpha pre 6.2!
  2295. # Nifty self-installer!
  2296. #  
  2297. # 1.5b2        07/16/96
  2298. # -----------------------------------------------
  2299. #  Now works with Alpha 6.1 and higher.
  2300. #
  2301. # 1.5b3        07/18/96
  2302. # -----------------------------------------------
  2303. # Now works with Alpha 6.1 and higher.
  2304. # Added Floating menu...
  2305. #
  2306. # 1.5        10/22/96
  2307. # -----------------------------------------------
  2308. # Slight bug fixes
  2309. #
  2310. # 1.5.1        10/23/96
  2311. # -----------------------------------------------
  2312. # Added some more apple event and floating palatte options.
  2313. #
  2314. # 1.5.2        11/02/96
  2315. # -----------------------------------------------
  2316. # Attempt to fix ome context switching weirdness
  2317. #
  2318. # 1.5.3        11/02/96
  2319. # -----------------------------------------------
  2320. # See 1.5.2
  2321. #
  2322. # 1.5.4        11/05/96
  2323. # -----------------------------------------------
  2324. # Added terminal output windows for PS/TeX/MIF/etc.
  2325. #
  2326. # 1.5.5        11/06/96
  2327. # -----------------------------------------------
  2328. # Added a "Scripts" menu which auto loads any script in gnuplots
  2329. #     "Scripts" folder (or subfolder)
  2330. # Made terminal output window creation faster
  2331. #
  2332. # 1.5.6        11/07/96
  2333. # -----------------------------------------------
  2334. # Fixed a few floating menu buggers
  2335. #
  2336. # 1.5.7        11/13/96
  2337. # -----------------------------------------------
  2338. # Check OUTP event for "Sorry, " string so that help for unknown item
  2339. #     will be sent to console rather than a new output terminal page
  2340. #
  2341. # 1.5.8        12/05/96
  2342. # -----------------------------------------------
  2343. # plot '-' now works
  2344. # Pause in demo-mode works better
  2345. # Added option to rebuild scripts menu
  2346. #
  2347. # 1.5.9        12/05/96
  2348. # -----------------------------------------------
  2349. # Repaired broken pwd display
  2350. #
  2351. # 1.5.9b    12/10/96
  2352. # -----------------------------------------------
  2353. # Repaired broken scripts menu
  2354. # Added a "edit scripts" menu----eventually, this one will go away,
  2355. #     but the functionality will be retained
  2356. #
  2357. # 1.6        12/23/96
  2358. # -----------------------------------------------
  2359. # Floating palatte now very useful.  User can run a script by selecting
  2360. #     a script menu item, or edit the script by selecting the script menu
  2361. #     item with the option key held down
  2362. #
  2363. # 1.7-1.9     12/05/00
  2364. # -----------------------------------------------
  2365. # Various updates by Vince.
  2366. #
  2367. # 2.0     12/05/00
  2368. # -----------------------------------------------
  2369. # An update by Craig for distribution with Alpha 7.4.
  2370. # Added "graphButton/killGraphButton" to menu.
  2371. # Added a simple "plot" electric.
  2372. # ===========================================================================
  2373.